package utils;

import java.text.Collator;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

import beans.OperateGoodsDetailsBean;
import beans.TimeoutBean;

/**
 * Created by Administrator on 2018/8/13.
 */

public class InventorySortUtils {

    public static void sortGoodsName(List<OperateGoodsDetailsBean.DataBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<OperateGoodsDetailsBean.DataBean>() {
                @Override
                public int compare(OperateGoodsDetailsBean.DataBean o1, OperateGoodsDetailsBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getGoodName(), o1.getGoodName()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getGoodName(), o1.getGoodName()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<OperateGoodsDetailsBean.DataBean>() {
                @Override
                public int compare(OperateGoodsDetailsBean.DataBean o1, OperateGoodsDetailsBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getGoodName(), o1.getGoodName()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getGoodName(), o1.getGoodName()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }



    }

    public static void sortGoodsSupplier(List<OperateGoodsDetailsBean.DataBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<OperateGoodsDetailsBean.DataBean>() {
                @Override
                public int compare(OperateGoodsDetailsBean.DataBean o1, OperateGoodsDetailsBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getManufacturer(), o1.getManufacturer()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getManufacturer(), o1.getManufacturer()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<OperateGoodsDetailsBean.DataBean>() {
                @Override
                public int compare(OperateGoodsDetailsBean.DataBean o1, OperateGoodsDetailsBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getManufacturer(), o1.getManufacturer()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getManufacturer(), o1.getManufacturer()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }

    }

    public static void sortGoodsSpecification(List<OperateGoodsDetailsBean.DataBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<OperateGoodsDetailsBean.DataBean>() {
                @Override
                public int compare(OperateGoodsDetailsBean.DataBean o1, OperateGoodsDetailsBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getSpecification(), o1.getSpecification()) < 0) {
                        return 1;
                    } else if (ca.compare(o2.getSpecification(), o1.getSpecification()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }

                }
            });
        } else {
            Collections.sort(list, new Comparator<OperateGoodsDetailsBean.DataBean>() {
                @Override
                public int compare(OperateGoodsDetailsBean.DataBean o1, OperateGoodsDetailsBean.DataBean o2) {
                    Collator ca = Collator.getInstance(Locale.CHINA);
                    if (ca.compare(o2.getSpecification(), o1.getSpecification()) > 0) {
                        return 1;
                    } else if (ca.compare(o2.getSpecification(), o1.getSpecification()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }

                }
            });
        }

    }

    public static void sortGoodsNumber(List<OperateGoodsDetailsBean.DataBean> list, boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<OperateGoodsDetailsBean.DataBean>() {
                @Override
                public int compare(OperateGoodsDetailsBean.DataBean o1, OperateGoodsDetailsBean.DataBean o2) {
                    if (o2.getNumber() - o1.getNumber() > 0) {
                        return 1;
                    } else if (o2.getNumber() - o1.getNumber() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<OperateGoodsDetailsBean.DataBean>() {
                @Override
                public int compare(OperateGoodsDetailsBean.DataBean o1, OperateGoodsDetailsBean.DataBean o2) {
                    if (o2.getNumber() - o1.getNumber() < 0) {
                        return 1;
                    } else if (o2.getNumber() - o1.getNumber() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }

    }

    public static void sortCabinet(List<OperateGoodsDetailsBean.DataBean> list,boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<OperateGoodsDetailsBean.DataBean>() {
                @Override
                public int compare(OperateGoodsDetailsBean.DataBean o1, OperateGoodsDetailsBean.DataBean o2) {
                    if (Integer.parseInt(o2.getSelectCabinet()) - Integer.parseInt(o1.getSelectCabinet()) < 0) {
                        return 1;
                    } else if (Integer.parseInt(o2.getSelectCabinet()) - Integer.parseInt(o1.getSelectCabinet()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<OperateGoodsDetailsBean.DataBean>() {
                @Override
                public int compare(OperateGoodsDetailsBean.DataBean o1, OperateGoodsDetailsBean.DataBean o2) {
                    if (Integer.parseInt(o2.getSelectCabinet()) - Integer.parseInt(o1.getSelectCabinet()) > 0) {
                        return 1;
                    } else if (Integer.parseInt(o2.getSelectCabinet()) - Integer.parseInt(o1.getSelectCabinet()) == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }

    public static void sortStatus(List<OperateGoodsDetailsBean.DataBean> list,boolean flag){

        if (flag) {
            Collections.sort(list, new Comparator<OperateGoodsDetailsBean.DataBean>() {
                @Override
                public int compare(OperateGoodsDetailsBean.DataBean o1, OperateGoodsDetailsBean.DataBean o2) {
                    if (o2.getStatus() - o1.getStatus() < 0) {
                        return 1;
                    } else if (o2.getStatus() - o1.getStatus()  == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        } else {
            Collections.sort(list, new Comparator<OperateGoodsDetailsBean.DataBean>() {
                @Override
                public int compare(OperateGoodsDetailsBean.DataBean o1, OperateGoodsDetailsBean.DataBean o2) {
                    if (o2.getStatus() - o1.getStatus()  > 0) {
                        return 1;
                    } else if (o2.getStatus() - o1.getStatus() == 0) {
                        return 0;
                    } else {
                        return -1;
                    }
                }
            });
        }
    }
}
